
#define GPIOA *((volatile unsigned int*)0x10000000)
#define GPIOB *((volatile unsigned int*)0x00001004)
#define UART_DR *((volatile unsigned char*)0xff04)

#define GPIO0 *((volatile unsigned int*)0x00001008)
#define GPIO1 *((volatile unsigned int*)0x0000100C)
#define GPIO2 *((volatile unsigned int*)0x00001010)
#define RAM_START *((volatile unsigned int*)0x800020)
#define RAM_END *((volatile unsigned int*)0x1000000)
#define SPI_DR (*((volatile unsigned int*)0x10000004))
#define SPI_DIV (*((volatile unsigned int*)0x10000008))
#define SECTION(x)                  __attribute__((section(x)))
void SECTION("FSymTab") puts(char*str)
{
    unsigned int i;
    for(i=0;str[i] != 0;i++)
    {
        UART_DR = str[i];
    }
}
void puts2(char*str)
{
    unsigned int i;
    for(i=0;str[i] != 0;i++)
    {
        UART_DR = str[i];
    }
}
const char hextable[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
void  printInt(char*str1,unsigned int data)
{
    char str2[9] = {0};
    unsigned char ch,i;
    puts(str1);
    for(i=0;i<8;i++)
    {
        ch = (unsigned char )data;
        ch = ch &0xf;
        data>>=4;
        str2[7 - i] = hextable[ch];
    }
    str2[8]=0;
    puts(str2);
    puts("\n");
}

extern unsigned int get_sp(void);
unsigned int data_test=0x55aa30;
void  irq(unsigned int irq,unsigned int *p,unsigned int sp) 
{
    unsigned int i;

    if((irq&0x20000000)==0x20000000)
    {
        printInt("error inst 0x",*p);
        printInt("addr 0x",p);
        while(1);
    }
    printInt("irq:0x",irq);
    printInt("pc:0x",p);
    printInt("sp:0x",sp);
    puts("irq1\r\n");
    while (1)
    {
        /* code */
    }
    
}

int main(void)
{
    volatile unsigned int i;
    unsigned int j = 1;
    void (*p)();
    SPI_DIV = 1;
    while(1)
    {
        j = SPI_DR;
        printInt("rw:",j);
    if(0x8000 == (j&0x8000))
    {
        SPI_DR = 0x55;
    }
    else
    {
        
    }
    }
//set_reg(10000); 
// set_irq(0x0fffffff);
 asm("ecall");
//waitirq();

while(1);
    return 0;
}